package org.rslai.tcedit.domain;

import java.sql.Clob;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;
import javax.persistence.Transient;
import org.hibernate.validator.Length;
import org.rslai.tcedit.util.StrUtil;

/**
 * 测试结果
 * 
 * @author rslai
 */
@MappedSuperclass
public class TestResult extends UUIDSupport {

	private Version version; // 版本信息
	private String testPlanID; // 测试计划id
	private String testCaseID; // 测试用例id
	private ExecuteState executeState; // 测试用例执行状态
	private String bugNO; // BUG 编号
	private Clob actualResult; // 实际结果
	private String actualResultStr; // 实际结果 字符串
	private Date exStartTime; // 测试用例执行开始时间
	private Date exEndTime; // 测试用例执行结束时间
	private int exTime; // 测试用例执行时间（秒）
	private User user; // 用户信息（测试用例执行人）

	@OneToOne
	@JoinColumn(nullable = false, updatable = true, unique = false)
	public Version getVersion() { return version; }
	public void setVersion(Version version) { this.version = version; }

	@Column(nullable = false, length = 32)
	public String getTestPlanID() { return testPlanID; }
	public void setTestPlanID(String testPlanID) { this.testPlanID = testPlanID; }

	@Column(nullable = false, length = 32)
	public String getTestCaseID() { return testCaseID; }
	public void setTestCaseID(String testCaseID) { this.testCaseID = testCaseID; }

	@OneToOne
	@JoinColumn(nullable = false, updatable = true, unique = false)
	public ExecuteState getExecuteState() { return executeState; }
	public void setExecuteState(ExecuteState executeState) { this.executeState = executeState; }

	@Column(nullable = true, length = 6)
	@Length(max = 6, message = "BUG 编号请限制在6字以内")
	public String getBugNO() { return bugNO; }
	public void setBugNO(String bugNO) { this.bugNO = bugNO; }

	@Lob
	@Basic(fetch = FetchType.LAZY) 
	@Column(nullable = true, length = 16777216)   
	public Clob getActualResult() { return actualResult; }
	public void setActualResult(Clob actualResult) {
		this.actualResult = actualResult;
		this.actualResultStr = StrUtil.toString(actualResult);
	}
	@Transient
	public String getActualResultStr() { return actualResultStr; }
	@Transient
	public void setActualResultStr(String actualResultStr) {
		this.actualResultStr = actualResultStr;
		this.actualResult = StrUtil.toClob(actualResultStr);
	}

	@Column(nullable = false)
	public Date getExStartTime() { return exStartTime; }
	public void setExStartTime(Date exStartTime) { this.exStartTime = exStartTime; }

	@Column(nullable = false)
	public Date getExEndTime() { return exEndTime; }
	public void setExEndTime(Date exEndTime) { this.exEndTime = exEndTime; }

	@Column(nullable = false)
	public int getExTime() { return exTime; }
	public void setExTime(int exTime) { this.exTime = exTime; }

	@OneToOne
	@JoinColumn(nullable = false, updatable = true, unique = false)
	public User getUser() { return user; }
	public void setUser(User user) { this.user = user; }

}
